home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d13 / pj9_3.arc / PIXELPAN.ASM < prev    next >
Assembly Source File  |  1991-10-07  |  7KB  |  197 lines

  1. ; PIXELPAN.ASM -- EGA/VGA Pixel Panning routines
  2. ; BY PEDER JUNGCK ( Copyright 1991 )
  3. ; Assembly language routines designed for C-style calling conventions
  4. ; All example routines use a near call model
  5. ; NOTE: the SetLineLength function is error trapped for Mode 0Dh (320x200)
  6.  
  7. SLOW_EGA equ 0
  8.  
  9.         .model small
  10.         .code
  11.  
  12. Public _Video_Mode              ; (int Mode) 
  13. Public _SetLineLength           ; (int Length)    
  14. Public _SetViewPosition         ; (HPixel,LineNum)
  15. Public _Set_Pixel               ; (x,y,Color)
  16.  
  17. BytesPerLine    dw      40      ; screen width in bytes (320x200 Mode)
  18. VOffset         equ     0a000h  ; video RAM offset
  19.  
  20. Video_ModeParms struc
  21.         dw     ?        ; pushed BP
  22.         dw     ?        ; return address pushed by call
  23.     vm_mode     dw     ?        ; pass new video mode parameter 
  24. Video_ModeParms ends
  25.  
  26. _Video_Mode     proc    near    ; void Video_Mode(int Mode);
  27.         push    bp
  28.         mov     bp,sp           ; put sp in bp, to get parameters on stack
  29.         mov     ax,[bp+vm_mode]
  30.         xor     ah,ah           ; set video mode ( ah=0 )
  31.         int     10h             ; call video BIOS
  32.         pop     bp
  33.         ret
  34. _Video_Mode endp
  35.  
  36. SetLineLengthParms   struc
  37.                 dw     ?        ; pushed BP
  38.                 dw     ?        ; return address pushed by call
  39.     LineLen     dw     ?        ; pass new scan line length
  40. SetLineLengthParms ends
  41.  
  42. _SetLineLength  proc    near    ; int SetLineLength(int Length)
  43.         push    bp
  44.         mov     bp,sp           ; put sp in bp, to find parameters on stack
  45.  
  46.         mov     ax,[bp+LineLen]
  47.         cmp     ax,40           ; Minimum Line Length (320x200) 40 bytes
  48.         jae     Low_OK          ;  1 page wide x 8 high (mode 0Dh default)
  49.  
  50.         mov     ax,40           ; Must be at least the minimum length
  51.         jmp     Hi_OK
  52.  
  53. Low_OK: cmp     ax,320          ; 320 bytes wide leaves only 200 high
  54.         jbe     Hi_OK           ;  8 pages wide and one high (mode 0Dh)
  55.         mov     ax,320          ; Must be less or equal to maximum
  56.  
  57. Hi_OK:  mov  BytesPerLine,ax
  58.         xchg    bx,ax           ; save parameter to BX
  59.         mov  dx,3d4h
  60.         mov  ax,13h
  61.         out  dx,ax              ; BytesPerVideoRamRow Func
  62.         inc  dx                 ; 3d5h data port
  63.         mov  ax,bx              ; number of lines to output
  64.         shr  ax,1               ; need words for port
  65.         out  dx,ax
  66.  
  67.         mov     ax,bx           ; return # of lines we set
  68.         pop     bp
  69.         ret
  70. _SetLineLength  endp
  71.  
  72. SetViewPositionParms   struc
  73.                 dw     ?        ; pushed BP
  74.                 dw     ?        ; return address pushed by call
  75.     Hpixel      dw     ?        ; pass in horizontal pixel offset
  76.     LineNum     dw     ?        ; pass in line number
  77. SetViewPositionParms   ends
  78.  
  79. _SetViewPosition proc near   ;void SetViewPosition(int HPixel,int Linenum)
  80.         push    bp
  81.         mov     bp,sp           ; put sp in bp, to find parameters on stack
  82.         mov     ax,[bp+HPixel]  ; get horizontal pixel address
  83.         mov     cx,ax           ;  and save in cx
  84.         and     cx,07           ; get pixel offset of position
  85.         shr     ax,1
  86.         shr     ax,1
  87.         shr     ax,1
  88.         xchg    bx,ax           ; and save in bx
  89.  
  90.         mov     ax,[bp+LineNum] ; get number of lines
  91.         mul     BytesPerLine    ; multiply times bytes per line 
  92.         add     bx,ax           ; new upper left corner offset
  93.  
  94.         mov     dx,3dah
  95. wait:   in      al,dx           ; make sure not already doing a retrace
  96.         test    al,08h
  97.         jz      wait
  98. Retrace: in     al,dx           ; wait until the start of retrace
  99.         test    al,08           ;  to perform clear of 3c0 port
  100.         jnz     Retrace
  101.  
  102.         cli                     ; disable interrupts
  103.         in      al,dx
  104.         mov     ax,bx           ; upper corner in AH, BH holds high value
  105.         mov     al,0ch          ; hi byte offset
  106.         mov     dx,3d4h
  107.         out     dx,ax
  108.         mov     al,0dh          ; low byte offset
  109.         mov     ah,bl           ; bl holds low byte value
  110.         out     dx,ax
  111. if SLOW_EGA
  112. ;*** add
  113.     sti
  114.     mov    dx,3dah
  115. wait2:    in    al,dx        ; wait til we start vertical retrace
  116.     test    al,08h
  117.     jz    wait2
  118.  
  119.     cli
  120. ;end add
  121. endif
  122.         mov     dx,3c0h         ; ATC index register
  123.         mov     al,33h          ; palette address source 1, reg address 13
  124.         out     dx,al           
  125.         xchg    cl,al           ; get pixel offset
  126.         out     dx,al
  127.  
  128.         sti                     ; enable interrupts
  129.         pop     bp
  130.         ret
  131. _SetViewPosition        endp
  132.  
  133. Set_PixelParms         struc
  134.                 dw     ?        ; pushed BP
  135.                 dw     ?        ; return address pushed by call
  136.     ps_xpos     dw     ?
  137.     ps_ypos     dw     ?
  138.     Color       dw     ?
  139. Set_PixelParms         ends
  140.  
  141. _Set_Pixel proc near         ; void Set_Pixel(int x, int y, int Color)
  142.         push    bp
  143.         mov     bp,sp
  144.         push    ds              ; save the data segment
  145.         mov     ax,VOffset      ; get the video RAM address
  146.         mov     ds,ax           ; set data segment to EGA/VGA
  147.         mov     ax,[bp+ps_ypos] ; get the y coordinate
  148.         mul     BytesPerLine    ; get the offset to line y
  149.         mov     bx,[bp+ps_xpos] ; get the x coordinate
  150.         mov     cx,bx           ; and save in CX
  151.         shr     bx,1            ;  and divide by 8
  152.         shr     bx,1
  153.         shr     bx,1
  154.         add     bx,ax           ; bx := BytesPerLine*y+(x/8) 
  155.                                 ; we now have x,y memory offset 
  156.         and    cl,7        ; generate mask for one pixel in byte
  157.         xor    cl,7
  158.         mov    ch,1
  159.         shl    ch,cl            ; ch := 1 >>>> (7-(x mod 8))
  160.  
  161.         mov    dx,3ceh          ; now select write mode 2
  162.         mov    al,5
  163.         out    dx,al            ; select mode (register 5)
  164.         mov    dx,3cfh
  165.         mov    al,2
  166.         out    dx,al            ; and set to write mode 2
  167.  
  168.         mov    dx,3ceh          ; set up mask
  169.         mov    al,8
  170.         out    dx,al            ; select mask (register 8)
  171.         mov    dx,3cfh
  172.         mov    al,ch
  173.         out    dx,al            ; set mask
  174.   
  175.         mov    al,[bx]          ; read from card and color dot
  176.         mov    ax,[bp+Color]
  177.         mov    [bx],al          ; write color to dot
  178.  
  179.         mov    dx,3ceh           ; restore default mode
  180.         mov    al,5
  181.         out    dx,al             ; select mode (register 5)
  182.         mov    dx,3cfh
  183.         mov    al,0
  184.         out    dx,al             ; set write mode back to 0
  185.         mov    dx,3ceh
  186.         mov    al,8
  187.         out    dx,al             ; select mask (register 8)
  188.         mov    dx,3cfh
  189.         mov    al,0ffh
  190.         out    dx,al             ; and set default mask
  191.         pop    ds                ; restore data segment
  192.         pop    bp
  193.         ret
  194. _Set_Pixel      endp
  195. end
  196.  
  197.